package jzbank.controller;
import io.swagger.annotations.*;
import jzbank.common.responsTool.Res;
import jzbank.pojo.comfig.FTPInstancePO;
import jzbank.service.FTPInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ftp")
@Api(tags = "FTP配置管理")
public class FTPInstanceController {

    @Autowired
    private FTPInstanceService service;

    /**
     * 添加FTP配置信息
     * @param ftpInstancePO FTP配置信息
     * @return 成功/失败
     */
    @ApiOperation("添加FTP配置信息")
    @ApiImplicitParam(name = "ftpInstancePO", value = "FTP配置信息", required = true, dataType = "FTPInstancePO")
    @PostMapping(value = "/create",  consumes = "application/json", produces = "application/json")
    public Res create(@RequestBody FTPInstancePO ftpInstancePO) {
        System.out.println("添加FTP配置：" + ftpInstancePO.toString());
        service.createFTPConfig(ftpInstancePO);
        return Res.ok();
    }

    /**
     * 查询所有FTP配置列表
     * @return FTP配置列表
     */
    @ApiOperation("查询所有FTP配置列表")
    @GetMapping("/list")
    public Res list() {
        System.out.println("查询FTP配置列表");
        List<FTPInstancePO> list = service.selectAllFTPConfigs();
        return Res.ok(list);
    }

    /**
     * 删除FTP配置
     * @param id FTP配置ID
     * @return
     */
    @ApiOperation("删除FTP配置")
    @ApiImplicitParam(name = "id", value = "FTP配置ID", required = true, dataType = "String")
    @PostMapping("/remove")
    public Res remove(@RequestParam String id) {
        System.out.println("删除FTP配置：" + id);
        service.deleteFTPConfigById(id);
        return Res.ok();
    }

    /**
     * 根据ID查询FTP配置
     * @param id FTP配置ID
     * @return FTP配置信息
     */
    @ApiOperation("根据ID查询FTP配置")
    @ApiImplicitParam(name = "id", value = "FTP配置ID", required = true, dataType = "String")
    @PostMapping("/get")
    public Res selectById(@RequestParam String id) {
        System.out.println("查询FTP配置：" + id);
        FTPInstancePO ftpInstancePO = service.selectFTPConfigById(id);
        return Res.ok(ftpInstancePO);
    }

    /**
     * 更新FTP配置信息
     * @param ftpInstancePO 新的FTP配置信息
     * @return 成功/失败
     */
    @ApiOperation("更新FTP配置信息")
    @ApiImplicitParam(name = "ftpInstancePO", value = "新的FTP配置信息", required = true, dataType = "FTPInstancePO")
    @PostMapping(value = "/update",  consumes = "application/json", produces = "application/json")
    public Res update(@RequestBody FTPInstancePO ftpInstancePO) {
        System.out.println("更新FTP配置：" + ftpInstancePO.toString());
        service.updateFTPConfig(ftpInstancePO);
        return Res.ok();
    }
}